package models

import (
	"fmt"
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	Name      string  `json:"name" gorm:"type:varchar(30);unique"`
	Price     float64 `json:"price" gorm:"type:decimal(10,2)"`
	Num       int     `json:"num" gorm:"int(10);index"`
	StartTime string  `json:"startTime" gorm:"type:datetime"`
	Intro     string  `json:"intro" gorm:"varchar(255)"`
}

func CreateGoods(goods *Goods) error {
	err := DB.Create(&goods).Error
	if err != nil {
		fmt.Println("添加失败")
		return err
	} else {
		fmt.Println("添加成功")
	}
	return nil
}
func GoodsLIst(goods []Goods) error {
	//err := DB.Model(&Goods{Name: name}).Where(name).Find(&goods).Error
	//if err != nil {
	//	return nil, err
	//}
	err = DB.Model(&Goods{}).Find(&goods).Error
	if err != nil {
		return err
	} else {
		fmt.Println("查询成功")
		return nil
	}
}
func Del(id int) error {
	err := DB.Delete(&gorm.Model{ID: uint(id)}).Error
	if err != nil {
		return err
	}
	return nil
}
